package com.pinganfu.tesla.iwallet;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.pinganfu.tesla.iwallet.session.SessionManager;
import com.pinganfu.tesla.iwallet.util.LogUtil;
import com.pinganfu.tesla.iwallet.util.QrcodeUtil;
import com.pinganfu.tesla.iwallet.util.TeslaUtil;

public class QrcodeActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_qrcode);

		((Button) findViewById(R.id.btnClose)).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}
		});

		String mobileNo = TeslaUtil.getCurrentMobileNo(this);
		TextView tvAcctName = (TextView) findViewById(R.id.tv_acct_name);
		SessionManager sm = SessionManager.getInstance();
		if (sm.getUserPref() != null) {
			tvAcctName.setText(sm.getUserPref().getMobileNo());
		}

		Display display = getWindowManager().getDefaultDisplay();
		Point size = new Point();
		display.getSize(size);
		int width = size.x;
		int height = size.y;

		LogUtil.i("width=" + width);
		LogUtil.i("height=" + height);

		int qrWidth = (int) (Math.min(width, height) * 0.9);

		ImageView imageQR = (ImageView) findViewById(R.id.imageQR);
		Bitmap bm = QrcodeUtil.createImage(mobileNo, qrWidth, qrWidth);
		imageQR.setImageBitmap(bm);
	}
}
